#include "gtest/gtest.h"
#include "Status.h"




const char * expectDefaultStatusString = "code:0,msg:nullptr";
const char * expectFailedString = "code:1,msg:nullptr";
using namespace streamdb;

TEST(StatusTest, use){
    {
        auto s = Status::OK();
        ASSERT_TRUE(s.isOk());
        ASSERT_STREQ(expectDefaultStatusString, s.toString().c_str());
    }

    {
        auto s = Status::Failed();
        ASSERT_TRUE(s.isFailed());
    }

}
TEST(StatusTest, move){
    //Move assign
    {
        auto s = Status::Failed();
        ASSERT_STREQ(expectFailedString, s.toString().c_str());

        Status failedStatus = std::move(s);
        ASSERT_STREQ(expectDefaultStatusString, s.toString().c_str());
        ASSERT_STREQ(expectFailedString, failedStatus.toString().c_str());
    }

    //Move constructor
    {
        auto s = Status::Failed();
        ASSERT_STREQ(expectFailedString, s.toString().c_str());

        Status failedStatus(std::move(s));
        ASSERT_STREQ(expectDefaultStatusString, s.toString().c_str());
        ASSERT_STREQ(expectFailedString, failedStatus.toString().c_str());
    }
}
TEST(StatusTest, copy){
    auto s = Status::Failed();
    ASSERT_STREQ(expectFailedString, s.toString().c_str());

    //Copy Constructor
    {
        auto news(s);
        ASSERT_STREQ(expectFailedString, news.toString().c_str());

    }
    //Copy Assign
    {
        auto news = s;
        ASSERT_STREQ(expectFailedString, news.toString().c_str());
    }
}


TEST(StatusTest, Equal){
    auto s = Status::Failed();

    auto failedStatus = Status::Failed();
    ASSERT_TRUE(s == failedStatus);

    auto ok = Status::OK();
    ASSERT_TRUE(s != ok);
}
